home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Problem Negating an Unsigned Char
- Date: 04 Mar 1996 15:19:21 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Mar4081921@qcd.lanl.gov>
- References: <Dnnros.Lq.0.-s@hkusuc.hku.hk> <4he27sINNdel@keats.ugrad.cs.ubc.ca>
- <DnqMyr.4pF@cwi.nl>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: dik@cwi.nl's message of Mon, 4 Mar 1996 10:11:15 GMT
-
- In article <DnqMyr.4pF@cwi.nl>
- dik@cwi.nl (Dik T. Winter) writes:
-
- <snip>
- DTW: > >unsigned char a=0x11;
- DTW: > >unsigned char b=0xEE;
- <snip>
- DTW: >
- DTW: > To make it portable, you must manually mask for the lower eight bits:
- DTW: >
- DTW: > if (a == (~b & 0xff))
- DTW:
- DTW: And how would this work on machines with other than eight bit chars?
- DTW: Casting to unsigned char will work regardless the number of bits
- in a char.
-
- I guess what the poster meant was that given the values of a and b,
- except on machines with 8 bit chars, (unsigned char)~b will not
- compare equal to a: whereas, ~b & 0xff will irrespective of the size
- of types. This happens to be true.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-